﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using OUSMS.AppLogic.DataAccessLayer;
namespace OUSMS.AppLogic.BusinessLogicLayer
{
    [System.ComponentModel.DataObject(true)]
    public class MotionFilesBLL : IDisposable
    {
        DatabaseContext _DatabaseContext;
        public MotionFilesBLL():this(new DatabaseContext())
        { 
        }

        public MotionFilesBLL(DatabaseContext DatabaseContext)
        {
            _DatabaseContext = DatabaseContext;
        }

        public void Dispose()
        {
            if (_DatabaseContext != null)
            {
                _DatabaseContext.Dispose();
                _DatabaseContext = null;
            }

            GC.SuppressFinalize(this);
        }

        public IQueryable<MotionFiles> GetMotionFilesByMotionID(long motionID)
        {
            return _DatabaseContext.MotionFiles.Where(m => m.MotionID == motionID && !m.IsDeleted);
        }

        public MotionFiles CreateMotionFiles(MotionFiles motionFiles)
        {
            motionFiles = _DatabaseContext.MotionFiles.Add(motionFiles);
            _DatabaseContext.SaveChanges();
            return motionFiles;
        }

        public void DeleteMotionFiles(MotionFiles motionFiles)
        {
            _DatabaseContext.MotionFiles.Remove(motionFiles);
            _DatabaseContext.SaveChanges();
        }

        public MotionFiles GetMotionFileByID(long motionFileID)
        {
            return _DatabaseContext.MotionFiles.Where(m => m.ID == motionFileID).FirstOrDefault();
        }
    }
}